package com.example.administrator.share;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.onekeyshare.OnekeyShare;

public class MainActivity extends AppCompatActivity {
 private Button but_1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        but_1= findViewById(R.id.but_1);
        but_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showShare();
            }
        });

    }
    private void showShare() {
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();
        oks.setSilent(true);
        oks.setTitle("标题");
        oks.setText("我是分享文本");
        oks.setTitleUrl("http://www.mob.com");
        oks.setUrl("http://www.mob.com");
        oks.setImageUrl("http://f1.webshare.mob.com/dimgs/1c950a7b02087bf41bc56f07f7d3572c11dfcf36.jpg");
        //        oks.setImagePath("/sdcard/1.jpg");
        oks.setCallback(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                Log.i("1234","onComplete");
                //                startActivity(new Intent(MainActivity.this,TwoAcitivity.class));

            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {
                Log.i("1234",throwable.toString());

            }

            @Override
            public void onCancel(Platform platform, int i) {
                Log.i("1234","onCancel");

            }
        });



        // 启动分享GUI
        oks.show(this);
    }
}
